import {
RIG_PLATFORM_CHART_VERSION
} from "../../../src/constants/versions"
import CodeBlock from '@theme/CodeBlock';

# Rig Platform

## Setup Installation

The Rig Platform is installed using a Helm chart, into any Kubernetes cluster that has
the Rig Operator installed.

## Dependencies

### Rig Operator

Ensure you have already [installed the Rig Operator](/operator-manual/setup-guide/operator)
before installing the Platform, as the Platform itself is installed as a Capsule.

### PostgreSQL

The Platform depends on a single PostgreSQL database, for where it will store all of its
configuration.

#### In-cluster database

It's possible to have the Helm Chart spin up a database by setting the following flag
when running `helm`: `--set postgres.enabled=true`. This is not recommended for production
environments though.

#### Managed database

The better option is to use a managed database in the cluster environment you're
already running in. It can also be a new database within an existing PostgreSQL instance.
Add the following section to your `platform.yaml` file:

```yaml title="Helm values - Platform"
rig:
  client:
    postgres:
      database: "rig"  ## change if different database is used.
      host: <host or ip>
      user: <db user>
      password: <db password>
      # insecure: false  ## set only if DB connection is insecure
```

:::info Note
See the [Database](/operator-manual/setup-guide/platform/database) article for more information about how to connect to your
own database, and other configuration options.
:::


## Configuration

In addition to database, the Rig Platform has a wide range of configuration options.
The configuration is easily provided as part of a values file for the Helm Chart.

The entire config is described [here](https://github.com/rigdev/rig/blob/main/deploy/charts/rig-platform/values.yaml),
but is simply a YAML file with configuration parameters.

### Applying the configuration

To apply a config to a cluster, save the file as `platform.yaml` run the following command:

<CodeBlock language="bash">
{`helm upgrade --install rig-platform rig-platform \\
  --repo https://charts.rig.dev \\
  --version ${RIG_PLATFORM_CHART_VERSION} \\
  --namespace rig-system \\
  --create-namespace \\
  -f platform.yaml
`}
</CodeBlock>

This can be done several times, after each change.

## Platform Initialization

After installing the Rig Platform you'll need to run the following command to setup an admin user

```bash
kubectl exec -it -n rig-system deploy/rig-platform rig-admin init
```

## Connect to the Rig Platform remotely

### Dashboard

Accessing the Dashboard is best done using an Ingress, but can also be done using port-forwarding:

```bash
kubectl port-forward -n rig-system service/rig-platform 4747
```

### CLI

After setting up Rig, users who want to connect to it remotely can run the following command using their local Rig CLI

```bash
rig config init
```
which will guide the user trough connecting to Rig.

